package com.nice.rm.util;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FileUtil {

    private static final Logger log = LoggerFactory.getLogger(FileUtil.class);

    public static void deleteFile(File file) {
	if (file == null)
	    return;
	if (file.isDirectory()) {
	    for (File f : file.listFiles()) {
		deleteFile(f);
	    }
	}
	file.delete();
	boolean delete = file.delete();
	log.info("delete  file:" + file + "->" + delete);
    }

    public static String strCat(Object... strs) {
	StringBuffer path = new StringBuffer();
	for (Object string : strs) {
	    path.append(string).append(' ');
	}
	return path.toString();

    }

    public static void close(Closeable... ios) {
	if (ios == null)
	    return;
	for (Closeable closeable : ios) {
	    if (closeable != null)
		try {
		    closeable.close();
		} catch (IOException e) {
		    log.error("fail to close " + closeable, e);
		}
	}
    }

    public static File buildDir(File path, String name, long curIndex) {
	return new File(path, name + curIndex);
    }
}
